import { ref, watch } from 'vue'
import Api from '@/api'


export default function useSlide(id) {

    const slideId = ref()
    const slideData = ref()

    watch(slideId, async (val) => {
        if(!val) return
        const res = await Api.getSpecimen(val)
        if(res.data.suffix == 'kfbzm' || res.data.suffix == 'dttzm' || res.data.suffix == 'odttzm'){
            const { suffix, tileSize, rate, width, length, imageAdjustment, encryptPath} = res.data
            delete imageAdjustment['zoom']

            slideData.value = {
                path: encryptPath,
                type: suffix,
                tileSize,
                zoom: rate,
                width,
                height: length,
                ...imageAdjustment
            }
        } else if(res.data.suffix == 'zmspe'){
            slideData.value = {
                path: res.data.resPath,
                type: res.data.suffix
            }
        } else if(res.data.suffix == 'jpg' || res.data.suffix == 'png'){
            slideData.value = {
                path: res.data.resPath,
                type: res.data.suffix
            }
        }
    })

    if(id) slideId.value = id



    return {
        slideId,
        slideData,
    }
}